<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // 浅拷贝只是拷贝一层，更深层次对象级别的只拷贝引用
        // 深拷贝拷贝多层，每一层级别的数据都会拷贝

        var obj = {
            id: 1,
            name: "andy",
            msg: {
                age: 18,
            },
        };
        var o = {};

        // 浅拷贝 原生js
        /*  
        for (var k in obj) {
            // console.log(k + '-' + obj[k]);
        }
*/

        // 浅拷贝
        Object.assign(o, obj);

        console.log(o);
        o.msg.age = 22;
        console.log(obj);
    </script>
</body>

</html>